#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, tt;

int stk[N];

int main() {
	cin >> n;
	while (n--) {
		string op;
		cin >> op;
		if (op == "push") {
			int x;
			cin >> x;
			stk[++tt] = x;
		} else if (op == "pop") {
			tt--;
		} else if (op == "empty") {
			cout << (tt ? "NO" : "YES") << endl;
		} else {
			cout << stk[tt] << endl;
		}
	}
	return 0;
}

